package com.ruoyi.employeeInfomation.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.List;

import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.web.service.SysRegisterService;
import com.ruoyi.salarydetails.domain.SalaryBreakdown;
import com.ruoyi.salarydetails.service.ISalaryBreakdownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.employeeInfomation.mapper.SalaryEmployeeMapper;
import com.ruoyi.employeeInfomation.domain.SalaryEmployee;
import com.ruoyi.employeeInfomation.service.ISalaryEmployeeService;

/**
 * 员工信息表Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-12
 */
@Service
public class SalaryEmployeeServiceImpl extends ServiceImpl<SalaryEmployeeMapper, SalaryEmployee> implements ISalaryEmployeeService {
    @Autowired
    private SalaryEmployeeMapper salaryEmployeeMapper;
    @Autowired
    private SysRegisterService registerService;
    @Autowired
    private ISalaryBreakdownService signaldownService;
    /**
     * 查询员工信息表
     *
     * @param id 员工信息表主键
     * @return 员工信息表
     */
    @Override
    public SalaryEmployee selectSalaryEmployeeById(Long id) {
        return salaryEmployeeMapper.selectSalaryEmployeeById(id);
    }

    /**
     * 查询员工信息表列表
     *
     * @param salaryEmployee 员工信息表
     * @return 员工信息表
     */
    @Override
    public List<SalaryEmployee> selectSalaryEmployeeList(SalaryEmployee salaryEmployee) {
        return salaryEmployeeMapper.selectSalaryEmployeeList(salaryEmployee);
    }

    /**
     * 新增员工信息表
     *
     * @param salaryEmployee 员工信息表
     * @return 结果
     */
    @Override
    public int insertSalaryEmployee(SalaryEmployee salaryEmployee) {
                salaryEmployee.setCreateTime(DateUtils.getNowDate());
             salaryEmployee.setJobNumber(String.valueOf(IdUtil.createSnowflake(5,1).nextId()));
       // System.out.println(salaryEmployee.getJobNumber());
        RegisterBody user = new RegisterBody();
        user.setUsername(salaryEmployee.getJobNumber());
        user.setPassword("123456");
        registerService.register(user);
        //在新增用户的时候给他的薪资明细也添加进去
        SalaryBreakdown salaryBreakdown = new SalaryBreakdown();
        salaryBreakdown.setJobNum(salaryEmployee.getJobNumber());
        //底薪
        salaryBreakdown.setSalary(salaryEmployee.getSalary());
        //绩效
        salaryBreakdown.setPerformance(BigDecimal.valueOf(0));
        //奖金
        salaryBreakdown.setBonus(BigDecimal.valueOf(0));
        //销售提成
        salaryBreakdown.setSalesCommissions(BigDecimal.valueOf(0));
        //社保
        salaryBreakdown.setSocialSecurity(BigDecimal.valueOf(0));
        //公积金
        salaryBreakdown.setAccumulationFund(BigDecimal.valueOf(0));
        //个人所得税
        salaryBreakdown.setPersonalIncomeTax(BigDecimal.valueOf(0));
        //请假
        salaryBreakdown.setLeaveMoney(BigDecimal.valueOf(0));
        //应发工资
        salaryBreakdown.setWagesShouldBePaid(BigDecimal.valueOf(0));
        //实发工资
        salaryBreakdown.setActualWages(BigDecimal.valueOf(0));
        signaldownService.insertSalaryBreakdown(salaryBreakdown);
        return salaryEmployeeMapper.insertSalaryEmployee(salaryEmployee);

    }
    /**
     * 修改员工信息表
     *
     * @param salaryEmployee 员工信息表
     * @return 结果
     */
    @Override
    public int updateSalaryEmployee(SalaryEmployee salaryEmployee) {
                salaryEmployee.setUpdateTime(DateUtils.getNowDate());
        return salaryEmployeeMapper.updateSalaryEmployee(salaryEmployee);
    }

    /**
     * 批量删除员工信息表
     *
     * @param ids 需要删除的员工信息表主键
     * @return 结果
     */
    @Override
    public int deleteSalaryEmployeeByIds(Long[] ids) {
        return salaryEmployeeMapper.deleteSalaryEmployeeByIds(ids);
    }

    /**
     * 删除员工信息表信息
     *
     * @param id 员工信息表主键
     * @return 结果
     */
    @Override
    public int deleteSalaryEmployeeById(Long id) {
        return salaryEmployeeMapper.deleteSalaryEmployeeById(id);
    }


}